{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from scipy.spatial.transform import Rotation as R\n",
    "from astropy import coordinates as ac\n",
    "import copy\n",
    "import torch\n",
    "\n",
    "import os \n",
    "from os.path import join, split,exists, isdir,isfile\n",
    "\n",
    "file_root =  join(os.getcwd(),'..')\n",
    "os.chdir(file_root)\n",
    "\n",
    "from utils.pc_utils import *\n",
    "from utils import * \n",
    "\n",
    "\n",
    "from utils.utils import * \n",
    "import numpy as np \n",
    "\n",
    "\n",
    "from entity.prediction_loader import PredictionLoader,MultiPredictionLoader\n",
    "\n",
    "from entity.semantic_kitti_gt_loader import SementicKittiGtLoader,MultiSementicKittiGtLoader\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "# loader = MultiSementicKittiGtLoader('datasets/dataset',['08','09'])\n",
    "loader = MultiSementicKittiGtLoader('datasets/dataset',['08','09','10'])\n",
    "\n",
    "\n",
    "pred_loader = MultiPredictionLoader('datasets/predictions/Jan19_four_losses_with_shapenet_anomaly/model_epoch_39',['08'])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6863 datasets/dataset/sequences/08/labels/000000.label\n",
      "4071 ('datasets/predictions/Jan19_four_losses_with_shapenet_anomaly/model_epoch_39/sequences/08/point_predict/000000.label', 'datasets/predictions/Jan19_four_losses_with_shapenet_anomaly/model_epoch_39/sequences/08/uncertainty/000000.label')\n"
     ]
    }
   ],
   "source": [
    "print(len(loader),loader[0])\n",
    "print(len(pred_loader),pred_loader[0])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(6863, 'datasets/dataset/sequences/08/labels/000000.label')"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(loader),loader[0]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "model_epoch_0 is mapped \n",
      "model_epoch_1 is mapped \n",
      "model_epoch_2 is mapped \n",
      "model_epoch_3 is mapped \n",
      "model_epoch_4 is mapped \n",
      "model_epoch_5 is mapped \n",
      "model_epoch_6 is mapped \n",
      "model_epoch_7 is mapped \n",
      "model_epoch_8 is mapped \n",
      "model_epoch_9 is mapped \n",
      "model_epoch_10 is mapped \n",
      "model_epoch_11 is mapped \n",
      "model_epoch_12 is mapped \n",
      "model_epoch_13 is mapped \n",
      "model_epoch_14 is mapped \n",
      "model_epoch_15 is mapped \n",
      "model_epoch_16 is mapped \n",
      "model_epoch_17 is mapped \n",
      "model_epoch_18 is mapped \n",
      "model_epoch_19 is mapped \n",
      "model_epoch_20 is mapped \n",
      "model_epoch_21 is mapped \n",
      "model_epoch_22 is mapped \n",
      "model_epoch_23 is mapped \n",
      "model_epoch_24 is mapped \n",
      "model_epoch_25 is mapped \n",
      "model_epoch_26 is mapped \n",
      "model_epoch_27 is mapped \n",
      "model_epoch_28 is mapped \n",
      "model_epoch_29 is mapped \n",
      "model_epoch_30 is mapped \n",
      "model_epoch_31 is mapped \n",
      "model_epoch_32 is mapped \n",
      "model_epoch_33 is mapped \n",
      "model_epoch_34 is mapped \n",
      "model_epoch_35 is mapped \n",
      "model_epoch_36 is mapped \n",
      "model_epoch_37 is mapped \n",
      "model_epoch_38 is mapped \n",
      "model_epoch_39 is mapped \n",
      "model_epoch_40 is mapped \n",
      "model_epoch_41 is mapped \n",
      "model_epoch_42 is mapped \n",
      "model_epoch_43 is mapped \n",
      "model_epoch_44 is mapped \n",
      "model_epoch_45 is mapped \n",
      "model_epoch_46 is mapped \n",
      "model_epoch_47 is mapped \n",
      "model_epoch_48 is mapped \n",
      "model_epoch_49 is mapped \n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "Author: daniel\n",
    "Date: 2023-03-21 16:15:50\n",
    "LastEditTime: 2023-03-21 20:54:54\n",
    "LastEditors: daniel\n",
    "Description: \n",
    "FilePath: /semantic_kitti_api-master/jupyters/vis_remap.ipynb\n",
    "have a nice day\n",
    "'''\n",
    "\n",
    "\n",
    "\n",
    "semantic_gt_loader = SementicKittiGtLoader('datasets/dataset')\n",
    "prediction_root = 'datasets/predictions/Jan19_four_losses_with_shapenet_anomaly'\n",
    "epoch_names= sorted(os.listdir(prediction_root),key=lambda k: int(k.split('_')[-1]))\n",
    "\n",
    "for epoch_name in epoch_names:\n",
    "    loader = PredictionLoader(join(prediction_root,epoch_name),'08')\n",
    "    # loader.tmp()\n",
    "    if loader.is_mapped() and loader.__len__() == semantic_gt_loader.__len__() :  \n",
    "        print(epoch_name,'is mapped ')\n",
    "    else :\n",
    "        print(epoch_name,'is not  mapped ')\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "pc_pred, uncertainty=loader.__getitem__(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((array([70, 70, 70, ..., 48, 48, 48], dtype=uint32),\n",
       "  array([0.43997207, 0.43997207, 0.6916288 , ..., 0.04604327, 0.04604327,\n",
       "         0.04604327], dtype=float32)),\n",
       " ('datasets/predictions/Jan19_four_losses_with_shapenet_anomaly/model_epoch_49/sequences/08/point_predict/000000.label',\n",
       "  'datasets/predictions/Jan19_four_losses_with_shapenet_anomaly/model_epoch_49/sequences/08/uncertainty/000000.label'))"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "loader.getitem(0), loader[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## check label "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "from entity.semantic_kitti_gt_loader import SementicKittiGtLoader\n",
    "\n",
    "gt_loader = SementicKittiGtLoader('datasets/dataset','08')\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "000000.label\n"
     ]
    }
   ],
   "source": [
    "sem,inst = gt_loader.get_label(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(array([  0,   1,  10,  11,  30,  40,  44,  48,  50,  51,  52,  70,  71,\n",
       "         72,  80,  81,  99, 252, 254], dtype=uint32),\n",
       " 123389,\n",
       " array([  0,   1,   2,   3,   9,  15,  24,  25, 194, 195, 196, 198],\n",
       "       dtype=uint32),\n",
       " 123389)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.unique(sem),len(sem),np.unique(inst),len(inst),"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "yang_real",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.13"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
